/*
 * @Description: 页面是否登录校验
 * @Date: 2021-03-10 10:13:49
 * @Author: 黄治恩
 */

import React from 'react';
import { Redirect, Route } from 'react-router-dom';
// import { useSelector } from 'react-redux';

import { RouteOption } from './routes';

const PrivatedRoute: React.FC<RouteOption> = (props) => {
  const { path, component: Component, routes } = props;
  // const TOKEN = useSelector(state => state.auth.token) || '';
  const TOKEN = 'xxx'
  // 没有登陆则跳转至登陆页
  if(!TOKEN) {
    return <Redirect path={path} to='/' />;
  }
  
  return (
    <Route path={path} render={(prop) => <Component {...prop} routes={routes} />}/>
  );
};

export default PrivatedRoute;